﻿#region Copyright information
// 
// Copyright © 2005-2013 Yongkee Cho. All rights reserved.
// 
// This code is a part of the Biological Object Library and governed under the terms of the
// GNU Lesser General  Public License (LGPL) version 2.1 which accompanies this distribution.
// For more information on the LGPL, please visit http://bol.codeplex.com/license.
// 
// - Filename: InteractorBase.cs
// - Author: Yongkee Cho
// - Email: yongkeecho@gmail.com
// - Date Created: 2013-01-25 3:25 PM
// - Last Modified: 2013-01-25 3:59 PM
// 
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;

namespace BOL.Models.MolecularInteractions
{
    [DataContract]
    public abstract class InteractorBase : IInteractor, IEquatable<IInteractor>
    {
        #region Public properties

        [DataMember]
        public string Id { get; private set; }

        [DataMember]
        public string Name { get; set; }

        [DataMember]
        public IEnumerable<string> Alternatives { get; set; }

        [DataMember]
        public IEnumerable<DbXref> DbXrefs { get; set; }

        #endregion

        #region Constructor

        protected InteractorBase(string id, string name, IEnumerable<string> alternatives, IEnumerable<DbXref> dbXrefs)
        {
            if (id == null)
                throw new ArgumentNullException("id");

            Id = id;
            Name = name;
            DbXrefs = dbXrefs;
            Alternatives = alternatives;
        }

        protected InteractorBase(string id, string name, IEnumerable<string> alternatives)
            : this(id, name, alternatives, Enumerable.Empty<DbXref>()) { }

        protected InteractorBase(string id, string name)
            : this(id, name, Enumerable.Empty<string>(), Enumerable.Empty<DbXref>()) { }

        protected InteractorBase(string id)
            : this(id, String.Empty, Enumerable.Empty<string>(), Enumerable.Empty<DbXref>()) { }

        #endregion

        #region IEquatable<IInteractor> implementation

        public bool Equals(IInteractor other)
        {
            return Id.Equals(other.Id);
        }

        #endregion

        #region Object overriden

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }

        public override bool Equals(object other)
        {
            if (other == null)
                throw new ArgumentNullException();

            if (!(other is IInteractor))
                throw new InvalidCastException("The 'other' argument is not an IInteractor object.");

            return Equals(other as IInteractor);
        }

        public override string ToString()
        {
            return String.IsNullOrEmpty(Name) ? Id : Name;
        }

        #endregion

    }
}
